<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'list.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	
  </head>
  
  <body>
    <table align="center" border="1">
    	<tr>
    		<td colspan="6"><h1>用户列表</h1></td>
    	</tr>
    	<tr>
    		<td colspan="6">
    			<form action="list" method="post">
    				<input type="hidden" name="pageNo" value=""/>
    				<input name="name" value="${name }">
    				<select name="deptId">
    					<option value="0">请选择</option>
    					<c:forEach var="list" items="${list}">
    						<option <c:if test="${deptId == list.deptId }">selected</c:if> value="${list.deptId }">${list.deptName }</option>
    					</c:forEach>
    				</select>
    				<input type="submit" value="查询"/>
    				<input type="reset" value="清空"/>  
    			</form>
    		</td>
    	</tr>
    	<tr>
    		<td>序号</td>
    		<td>用户账号</td>
    		<td>邮箱</td>
    		<td>所属部门</td>
    		<td>创建时间</td>
    		<td>操作</td>
    	</tr>
    	<c:forEach var="list" items="${page.list}" varStatus="status">
    		<tr <c:if test="${status.index%2==0}">style="background-color:#ccc;"</c:if> >
    			<td>${status.index+1 }</td>
    			<td>${list.userAccount }</td>
    			<td>${list.email }</td>
    			<td>${list.deptName}</td>
    			<td>${list.createDate }</td>
    			<td><a href="getupdate?id=${list.userid	}">修改</a><a id="${list.userid }">删除</a></td>
    		</tr>
    	</c:forEach>
    	<tr>
    		<td colspan="6" align="right">共${page.pageCount }页
    			<a onclick="dd(document.forms[0],1,${page.pageCount})">首页</a>
    			<a onclick="dd(document.forms[0],${page.pageNo-1},${page.pageCount})">上一页</a>
    			<a onclick="dd(document.forms[0],${page.pageNo+1},${page.pageCount})">下一页</a>
    			<a onclick="dd(document.forms[0],${page.pageCount},${page.pageCount})">末页</a>
    			第${page.pageNo }页
    		</td>
    	</tr>
    </table>
  </body>
  <script type="text/javascript" src="js/jquery-1.12.4.js"></script>
  <script type="text/javascript">
  	function dd(dom,pageNo,pageSize){
  		if(pageNo > 0 && pageNo <= pageSize){
  			$("[name=pageNo]").val(pageNo);
  			dom.submit();
  		}
  	}
  	
  	$(function(){
  		$("a[id]").click(function(){
  			var a = $(this);
  			var id = $(this).attr("id");
	  		$.post("del","id="+id,function(data){
	  			if(data == "true"){
	  				a.parent().parent().remove();
	  			}else{
	  				alert("删除失败!");
	  			}
	  		});
  	})
  	});
  	
  </script>
</html>
